import { reactive, toRefs } from "vue";
import { useVersion } from "@/stores/Version";

import { useCommon } from '@/stores/Common'
import { validateVersion } from "@/utils/Validate";

const CommonStore = useCommon()
const VersionStore = useVersion()
const { deviceTypeOptions } = toRefs(CommonStore)

export const searchConfig = reactive({
    deviceType: {
        component: 'ARadioGroup',
        label: '版本类型',
        attrs: {
            optionType: 'button',
            buttonStyle: "solid",
            options: [
                { label: '全部', value: '' },
                { label: '单锁控', value: '单锁控' },
                { label: '多锁控', value: '多锁控' },
            ],
            onChange(e: any) {
                VersionStore.searchForm.deviceType = e.target.value
            },
            style: {
                width: '100%'
            }
        }
    },
    versionId: {
        component: 'AInput',
        label: '版本号',
        attrs: {
            allowClear: true,
            placeholder: '版本号',
            style: {
                width: '100%'
            }
        }
    }
})

export const addConfig = reactive({
    versionId: {
        component: 'AInput',
        label: '版本号',
        attrs: {
            allowClear: true,
            placeholder: '版本号',
            style: {
                width: '100%'
            },
        },
        rules: [{ required: true, validator: validateVersion, trigger: 'blur' }]
    },
    deviceType: {
        component: 'ASelect',
        label: '版本类型',
        attrs: {
            options: deviceTypeOptions,
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请选择版本类型', trigger: 'blur' }]
    },
    updateInfo: {
        component: 'ATextarea',
        label: '更新内容',
        attrs: {
            allowClear: true,
            placeholder: '更新内容',
            rows: 4,
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '更新内容不能为空', trigger: 'blur' }]
    },
    file: {
        component: 'Upload',
        label: '文件',
        attrs: {
            showAPK: true,
            selectedFn: (file: File) => {
                VersionStore.addForm.file = [file]
            },
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '文件不能为空', trigger: 'blur' }]
    }
})

export const columns = [
    {
        title: '序号',
        dataIndex: 'index',
        align: 'center',
        width: 80,
        fixed: 'left'
    }, {
        title: '版本号',
        dataIndex: 'versionId',
        width: 150,
        align: 'center',
    }, {
        title: '版本类型',
        dataIndex: 'deviceType',
        width: 150,
        align: 'center',
    }, {
        title: '版本链接',
        dataIndex: 'download',
        width: 300,
        align: 'center',
    }, {
        title: '上传日期',
        dataIndex: 'updateData',
        width: 150,
        align: 'center',
    }, {
        title: '操作',
        dataIndex: 'action',
        width: 150,
        align: 'center',
    }
]